<template>
  <div class="app-container">
    <el-row :gutter="30">
      <el-col :span="24">
        <div style="margin-top:10px">
          <el-button icon="el-icon-rank" type="primary" size="mini" @click="mergeData" v-if="d">合并</el-button>
          <el-button icon="el-icon-close" type="danger" size="mini" @click="deleteAny" v-if="d">删除</el-button>
        </div>
        <div class="query-form" v-if="p">
          <el-form ref="tableSearchParam" :model="tableSearchParam" label-width="50px" :inline="true">
            <el-form-item label="公司名称" label-width="70px">
              <el-input v-model="tableSearchParam.companyName" style="width:200px" size="small" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="listTableData" icon="el-icon-search" size="small">查询</el-button>
            </el-form-item>
          </el-form>
        </div>
        <br/>
        <el-table
          :data="tableData"
          border
          empty-text="暂无数据"
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            width="35">
          </el-table-column>
          <el-table-column
            label="公司名称"
            property="companyName"
            width="100">
          </el-table-column>
          <el-table-column
            label="所在省份"
            width="70">
            <template slot-scope="scope">
              <span v-if="scope.row.region">{{scope.row.region.split(',')[0]}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="所在城市"
            width="70">
            <template slot-scope="scope">
              <span v-if="scope.row.region">{{scope.row.region.split(',')[1]}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="加入来源"
            width="130">
            <template slot-scope="scope">
              <span>{{scope.row.companyFrom == '0' ? '救援公司负责人认证' : '救援司机认证'}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="负责人姓名"
            property="employeeName"
            width="90">
          </el-table-column>
          <el-table-column
            label="负责人手机"
            property="telphone"
            width="100">
          </el-table-column>
          <el-table-column
            label="司机数量"
            property="driverNum"
            width="70">
          </el-table-column>
          <el-table-column label="操作" width="550">
            <template slot-scope="scope">
              <el-button
                size="mini"
                icon="el-icon-view"
                v-if="v"
                @click="viewData(scope.$index, scope.row)">查看
              </el-button>
              <el-button
                size="mini"
                icon="el-icon-edit"
                type="success"
                v-if="b"
                @click="editData(scope.$index, scope.row)">编辑
              </el-button>
              <el-button
                size="mini"
                icon="el-icon-lemone-user_role"
                v-if="ur"
                @click="editManager(scope.$index, scope.row)">变更负责人
              </el-button>
              <el-button
                size="mini"
                icon="el-icon-edit"
                type="warning"
                v-if="a"
                @click="editTemplate(scope.$index, scope.row)">设置工单模板
              </el-button>
              <el-button
                size="mini"
                type="danger"
                icon="el-icon-close"
                v-if="d"
                @click="handleDelete(scope.$index, scope.row)">删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="page" v-if="p">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page=this.currentPage
            :page-sizes="[10, 20, 30, 40]"
            :page-size=this.pageSize
            layout="total, sizes, prev, pager, next, jumper"
            :total=this.total>
          </el-pagination>
        </div>
      </el-col>
    </el-row>

    <el-dialog title="修改公司信息" :visible.sync="dialogFormVisible" top="10vh" width="70%">
      <div style="height:400px;overflow-y: auto">
        <el-form :model="formData" :rules="rules" ref="ruleForm" style="margin-left: 20px">
          <el-row>
            <el-col :span="4" class="m-col">公司名称</el-col>
            <el-col :span="8" class="m-col-left">
              <el-input v-model="formData.companyName" auto-complete="off" style="width:255px"></el-input>
            </el-col>
            <el-col :span="4" class="m-col-left">加入来源</el-col>
            <el-col :span="8" class="m-col-left"><span>{{formData.companyFrom == '0' ? '救援公司负责人认证' : '救援司机认证'}}</span>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="m-col">负责人姓名</el-col>
            <el-col :span="8" class="m-col-left"><span>{{formData.employeeName}}</span></el-col>
            <el-col :span="4" class="m-col-left">负责人手机</el-col>
            <el-col :span="8" class="m-col-left"><span>{{formData.telphone}}</span></el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="m-col">所在区域</el-col>
            <el-col :span="8" class="m-col-left">
              <el-cascader
                size="small"
                style="width:255px"
                :options="options"
                v-model="selectedOptions"
                @change="handleChange">
              </el-cascader>
            </el-col>
            <el-col :span="4" class="m-col-left">联系地址</el-col>
            <el-col :span="8" class="m-col-left">
              <el-input v-model="formData.address" auto-complete="off" style="width:255px"></el-input>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="m-col">英文名称</el-col>
            <el-col :span="8" class="m-col-left">
              <el-input v-model="formData.companyEnglishName" auto-complete="off" style="width:255px"></el-input>
            </el-col>
            <el-col :span="4" class="m-col">联系电话</el-col>
            <el-col :span="8" class="m-col-left">
              <el-input v-model="formData.companyTelphone" auto-complete="off" style="width:255px"></el-input>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="m-col">官网网址</el-col>
            <el-col :span="20" class="m-col-left">
              <el-input v-model="formData.companyWebsiteUrl" auto-complete="off" style="width:255px"></el-input>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="m-col-bottom" style=" border-top: 1px solid #ebeef5;">公司LOGO</el-col>
            <el-col :span="20" class="m-col-bottom-left" style=" border-top: 1px solid #ebeef5;">
              <el-upload style="margin-top:10px"
                         :file-list="logoImgs"
                         :action="uploadUrl"
                         list-type="picture-card"
                         :on-preview="handlePictureCardPreview"
                         :on-remove="handleRemove"
                         :on-success="handleSuccess"
                         :limit="1">
                <i class="el-icon-plus"></i>
              </el-upload>
              <!--<div style="margin-top: 25px" v-if="formData.companyLogo!=null">-->
              <!--<div style="width: 100px;height: 100px" @click="showImg(formData.companyLogo.url)">-->
              <!--<img :src="formData.companyLogo==null?'':baseUrl+formData.companyLogo.url"-->
              <!--style="width:100%;height:100%"></img>-->
              <!--</div>-->
              <!--</div>-->
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="m-col-bottom" style=" border-top: 1px solid #ebeef5;">公众号二维码</el-col>
            <el-col :span="20" class="m-col-bottom-left" style=" border-top: 1px solid #ebeef5;">
              <el-upload style="margin-top:10px;"
                         :file-list="qrcodeImgs"
                         :action="uploadUrl"
                         list-type="picture-card"
                         :on-preview="handlePictureCardPreview"
                         :on-remove="handleRemove1"
                         :on-success="handleSuccess1"
                         :limit="1">
                <i class="el-icon-plus"></i>
              </el-upload>
              <!--<div style="margin-top: 25px" v-if="formData.companyLogo!=null">-->
              <!--<div style="width: 100px;height: 100px" @click="showImg(formData.companyLogo.url)">-->
              <!--<img :src="formData.companyLogo==null?'':baseUrl+formData.companyLogo.url"-->
              <!--style="width:100%;height:100%"></img>-->
              <!--</div>-->
              <!--</div>-->
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="m-col-bottom" style=" border-top: 1px solid #ebeef5;">营业执照</el-col>
            <el-col :span="20" class="m-col-bottom-left" style=" border-top: 1px solid #ebeef5;">
              <el-upload style="margin-top:10px"
                         :file-list="businessImgs"
                         :action="uploadUrl"
                         list-type="picture-card"
                         :on-preview="handlePictureCardPreview"
                         :on-remove="handleRemove2"
                         :on-success="handleSuccess2"
                         :limit="1">
                <i class="el-icon-plus"></i>
              </el-upload>
              <!--<div style="margin-top: 25px" v-if="formData.businessLicense!=null">-->
              <!--<div style="width: 100px;height: 100px" @click="showImg(formData.businessLicense.url)">-->
              <!--<img :src="formData.businessLicense==null?'':baseUrl+formData.businessLicense.url"-->
              <!--style="width:100%;height:100%"></img>-->
              <!--</div>-->
              <!--</div>-->
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="m-col-bottom" style="height:350px">身份证</el-col>
            <el-col :span="20" class="m-col-bottom-left" style="height:350px">
              <div style="margin-top: 25px" v-for="item in formData.idCards">
                <div style="width: 100px;height: 100px;float:left;both:clear;margin-left:20px"
                     @click="showImg(item.url)">
                  <img :src="baseUrl+item.url"
                       style="width:100%;height:100%;"></img>
                </div>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="m-col-bottom">负责人照片</el-col>
            <el-col :span="20" class="m-col-bottom-left">
              <div style="margin-top: 25px">
                <div style="width: 100px;height: 100px" @click="showImg(formData.applicants.url)">
                  <img :src="formData.applicants==null?'':baseUrl+formData.applicants.url"
                       style="margin-left:20px;width:100%;height:100%;"></img>
                </div>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleEdit" :loading="loading">保存</el-button>
      </div>
    </el-dialog>

    <el-dialog title="查看公司详情" :visible.sync="dialogViewFormVisible" top="10vh" width="70%">
      <div style="height:400px;overflow-y: auto">
        <!--<el-form :model="formData" :rules="rules" ref="ruleForm" style="margin-left: 20px">-->
        <el-row>
          <el-col :span="4" class="m-col">公司名称</el-col>
          <el-col :span="8" class="m-col-left"><span>{{formData.companyName}}</span></el-col>
          <el-col :span="4" class="m-col-left">加入来源</el-col>
          <el-col :span="8" class="m-col-left"><span>{{formData.companyFrom == '0' ? '救援公司负责人认证' : '救援司机认证'}}</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" class="m-col">负责人姓名</el-col>
          <el-col :span="8" class="m-col-left"><span>{{formData.employeeName}}</span></el-col>
          <el-col :span="4" class="m-col-left">负责人手机</el-col>
          <el-col :span="8" class="m-col-left"><span>{{formData.telphone}}</span></el-col>
        </el-row>
        <el-row>
          <el-col :span="4" class="m-col">所在区域</el-col>
          <el-col :span="20" class="m-col-left">
            {{formData.region}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" class="m-col">联系地址</el-col>
          <el-col :span="20" class="m-col-left">
            {{formData.address}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" class="m-col">英文名称</el-col>
          <el-col :span="8" class="m-col-left">
            {{formData.companyEnglishName}}
          </el-col>
          <el-col :span="4" class="m-col">联系电话</el-col>
          <el-col :span="8" class="m-col-left">
            {{formData.companyTelphone}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" class="m-col">官网网址</el-col>
          <el-col :span="20" class="m-col-left">
            {{formData.companyWebsiteUrl}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" class="m-col-bottom" style=" border-top: 1px solid #ebeef5;">公司LOGO</el-col>
          <el-col :span="20" class="m-col-bottom-left" style=" border-top: 1px solid #ebeef5;">
            <div style="margin-top: 25px" v-if="formData.companyLogo!=null">
              <div style="width: 100px;height: 100px" @click="showImg(formData.companyLogo.url)">
                <img :src="formData.companyLogo==null?'':baseUrl+formData.companyLogo.url"
                     style="width:100%;height:100%"></img>
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" class="m-col-bottom" style=" border-top: 1px solid #ebeef5;">公司二维码</el-col>
          <el-col :span="20" class="m-col-bottom-left" style=" border-top: 1px solid #ebeef5;">
            <div style="margin-top: 25px" v-if="formData.companyMpQrcode!=null">
              <div style="width: 100px;height: 100px" @click="showImg(formData.companyMpQrcode.url)">
                <img :src="formData.companyMpQrcode==null?'':baseUrl+formData.companyMpQrcode.url"
                     style="width:100%;height:100%"></img>
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" class="m-col-bottom" style=" border-top: 1px solid #ebeef5;">营业执照</el-col>
          <el-col :span="20" class="m-col-bottom-left" style=" border-top: 1px solid #ebeef5;">
            <div style="margin-top: 25px" v-if="formData.businessLicense!=null">
              <div style="width: 100px;height: 100px" @click="showImg(formData.businessLicense.url)">
                <img :src="formData.businessLicense==null?'':baseUrl+formData.businessLicense.url"
                     style="width:100%;height:100%"></img>
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" class="m-col-bottom" style="height:350px">身份证</el-col>
          <el-col :span="20" class="m-col-bottom-left" style="height:350px">
            <div style="margin-top: 25px" v-for="item in formData.idCards">
              <div style="width: 100px;height: 100px;float:left;both:clear;margin-left:20px"
                   @click="showImg(item.url)">
                <img :src="baseUrl+item.url"
                     style="width:100%;height:100%;"></img>
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4" class="m-col-bottom">负责人照片</el-col>
          <el-col :span="20" class="m-col-bottom-left">
            <div style="margin-top: 25px" v-if="formData.applicants!=null">
              <div style="width: 100px;height: 100px" @click="showImg(formData.applicants.url)">
                <img :src="formData.applicants==null?'':baseUrl+formData.applicants.url"
                     style="margin-left:20px;width:100%;height:100%;"></img>
              </div>
            </div>
          </el-col>
        </el-row>
        <!--</el-form>-->
      </div>
      <div slot="footer" class="dialog-footer">
        <!--<el-button @click="dialogFormVisible = false">取 消</el-button>-->
        <!--<el-button type="primary" @click="handleEdit" :loading="loading">保存</el-button>-->
      </div>
    </el-dialog>

    <el-dialog title="变更负责人" :visible.sync="dialogManagerFormVisible" top="10vh">
      <el-form :model="formManagerData" style="margin-left: 20px" :rules="rulesManager" ref="ruleManagerForm">
        <el-form-item label="负责人" :label-width="formLabelWidth" prop="newManagerId">
          <el-select v-model="formManagerData.newManagerId" placeholder="请选择" no-data-text="暂无数据" style="width:255px"
                     @change="managerSelectChange" filterable>
            <el-option
              v-for="item in allDriverData"
              :key="item.id"
              :label="item.employeeName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号" :label-width="formLabelWidth">
          <el-input v-model="formManagerData.telphone" auto-complete="off" style="width:255px" disabled></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogManagerFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleManager" :loading="loading">保存</el-button>
      </div>
    </el-dialog>
    <el-dialog title="设置模板" :visible.sync="dialogsFormVisible" top="10vh" width="55%">
      <el-form :model="formsData" style="margin-left: 150px">
        <el-form-item label="设置模板" :label-width="formLabelWidth" prop="name">
          <el-select v-model="formsData.templateId" placeholder="请选择" no-data-text="暂无数据" style="width:200px">
            <el-option
              v-for="item in allTemplateData"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleTemplate">保存</el-button>
      </div>
    </el-dialog>
    <el-dialog title="查看图片" :visible.sync="dialogImgFormVisible" top="10vh">
      <div style="text-align: center">
        <img :src="baseUrl+imgUrl" style="width:80%;height: auto">
      </div>
      <div slot="footer" class="dialog-footer">

      </div>
    </el-dialog>
    <el-dialog title="查看图片" :visible.sync="dialogImg1FormVisible" top="10vh">
      <div style="text-align: center">
        <img :src="imgUrl" style="width:80%;height: auto">
      </div>
      <div slot="footer" class="dialog-footer">

      </div>
    </el-dialog>
    <el-dialog title="选择合并目标公司" :visible.sync="dialogsMergeFormVisible" top="10vh" width="55%">
      <el-form :model="mergeFormData" style="margin-left: 150px">
        <el-form-item label="目标公司" :label-width="formLabelWidth" prop="name">
          <el-select v-model="mergeFormData.srcRescueCompanyId" placeholder="请选择" no-data-text="暂无数据"
                     style="width:200px">
            <el-option
              v-for="item in allRescueCompany"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleMerge">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<style scoped>

  .page {
    text-align: center;
    margin-top: 20px;
  }

  .query-form {
    border-bottom: 1px solid #ebeef5;
    padding-top: 25px;
  }

  .m-col {
    border: 1px solid #ebeef5;
    border-bottom: none;
    padding-left: 10px;
    height: 40px;
    line-height: 40px;
    color: #909399;
    font-weight: 500;
  }

  .m-col-left {
    border: 1px solid #ebeef5;
    border-left: none;
    border-bottom: none;
    padding-left: 10px;
    height: 40px;
    line-height: 40px;
  }

  .m-col-bottom {
    border: 1px solid #ebeef5;
    border-top: none;
    padding-left: 10px;
    height: 250px;
    line-height: 250px;
    color: #909399;
    font-weight: 500;
  }

  .m-col-bottom-left {
    border: 1px solid #ebeef5;
    border-top: none;
    border-left: none;
    padding-left: 10px;
    height: 250px;
    line-height: 250px;
  }

</style>

<script>

  import electronicWorksheetsTemplateApi from '@/api/electronicWorksheetsTemplateApi'
  import rescueCompanyApi from '@/api/rescueCompanyApi'
  import rescueEmployeeApi from '@/api/rescueEmployeeApi'
  import {provinceAndCityData, CodeToText, TextToCode} from 'element-china-area-data'

  export default {
    created() {
      this.ur = this.permissionValid.validAction(this.permissionValid.permissionRule.rescueCompany.updateRole)
      this.p = this.permissionValid.validAction(this.permissionValid.permissionRule.rescueCompany.listOperationRescueCompany)
      this.d = this.permissionValid.validAction(this.permissionValid.permissionRule.rescueCompany.removeRescueCompany)
      this.v = this.permissionValid.validAction(this.permissionValid.permissionRule.rescueCompany.getOperationById)
      this.a = this.permissionValid.validAction(this.permissionValid.permissionRule.workOrder.setWorktemplate)
      this.b = this.permissionValid.validAction(this.permissionValid.permissionRule.workOrder.updateRescueCompany)
      this.initData()
    },
    data() {
      return {
        ur: false,
        uploadUrl: process.env.BASE_API + '/admin/online/service/company/upload',
        dialogImg1FormVisible: false,
        logoImgs: [],
        qrcodeImgs: [],
        businessImgs: [],
        dialogsMergeFormVisible: false,
        mergeFormData: {
          srcRescueCompanyId: ''
        },
        allRescueCompany: [],
        baseUrl: process.env.IMG_BASE_URL,
        dialogViewFormVisible: false,
        dialogImgFormVisible: false,
        imgUrl: '',
        dialogsFormVisible: false,
        formsData: {
          templateId: ''
        },
        allTemplateData: [],
        p: false,
        d: false,
        v: false,
        allDriverData: [],
        options: provinceAndCityData,
        selectedOptions: [],
        tableData: [],
        currentPage: 1,
        pageSize: 10,
        total: 0,
        tableSearchParam: {
          companyName: ''
        },
        dialogManagerFormVisible: false,
        formManagerData: {
          companyId: '',
          newManagerId: '',
          telphone: ''
        },
        dialogFormVisible: false,
        formLabelWidth: '70px',
        formData: {
          companyName: '',
          employeeName: '',
          telphone: '',
          region: '',
          address: '',
          businessLicense: {},
          companyLogo: {},
          idCards: [],
          applicants: {}

        },
        loading: false,
        actionType: '',
        multipleSelection: [],
        rules: {
          name: [
            {required: true, message: '请输入平台名称', trigger: 'blur'},
            {max: 50, message: '长度不超过50 个字符', trigger: 'blur'}
          ]
        },
        rulesManager: {
          newManagerId: [
            {required: true, message: '请选择负责人', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      handlePictureCardPreview(file) {
        this.dialogImg1FormVisible = true
        this.imgUrl = file.url
      },
      handleSuccess(res, file) {
        this.formData.companyLogo = {
          id: '',
          url: res.data
        }
      },
      handleSuccess1(res, file) {
        this.formData.companyMpQrcode = {
          id: '',
          url: res.data
        }
      },
      handleSuccess2(res, file) {
        this.formData.businessLicense = {
          id: '',
          url: res.data
        }
      },
      handleRemove(file, fileList) {
        this.formData.companyLogo = null
        this.logoImgs.pop()
      },
      handleRemove1(file, fileList) {
        this.formData.companyMpQrcode = null
        this.qrcodeImgs.pop()
      },
      handleRemove2(file, fileList) {
        this.formData.businessLicense = null
        this.businessImgs.pop()
      },
      showImg(url) {
        this.dialogImgFormVisible = true
        this.imgUrl = url
      },
      editTemplate(index, row) {
        this.formsData.templateId = row.templateId
        electronicWorksheetsTemplateApi.listAllElectronicWorksheetsTemplate({}, (res) => {
          this.allTemplateData = res
          this.formsData.id = row.id
          this.dialogsFormVisible = true
        }, () => {
        })
      },
      handleTemplate() {
        rescueCompanyApi.setWorkTemplate(this.formsData.id, this.formsData.templateId, (res) => {
          this.dialogsFormVisible = false
          this.$message({
            message: '设置成功',
            type: 'success'
          })
          this.initData()
        }, () => {
        })
      },
      handleChange(value) {
        console.log(value)
        console.log(this.selectedOptions)
      },
      initData() {
        this.listTableData()
      },
      listTableData() {
        if (this.p) {
          rescueCompanyApi.listOperationRescueCompany(this.tableSearchParam, this.currentPage, this.pageSize, (res) => {
            this.tableData = res.list
            this.total = res.total
          }, () => {
          })
        } else {
          rescueCompanyApi.listRescueCompany(this.tableSearchParam, this.currentPage, this.pageSize, (res) => {
            this.tableData = res.list
            this.total = res.total
          }, () => {
          })
        }
      },
      mergeData() {
        if (this.multipleSelection.length == 0) {
          this.$message({
            message: '请选择被合并公司',
            type: 'warning'
          })
          return
        }
        rescueCompanyApi.listAllRescueCompany({}, (res) => {
          let newAllRescueCompany = []
          this.allRescueCompany = res
          for (var rc of this.allRescueCompany) {
            if (this.multipleSelection.indexOf(rc.id) == -1) {
              newAllRescueCompany.push(rc)
            }
          }
          this.allRescueCompany = newAllRescueCompany
          this.dialogsMergeFormVisible = true
        }, () => {
        })
      },
      handleMerge() {
        rescueCompanyApi.mergeFormData(this.mergeFormData.srcRescueCompanyId, this.multipleSelection, (res) => {
          this.$message({
            message: '合并成功',
            type: 'success'
          })
          this.initData()
          this.dialogsMergeFormVisible = false
        }, () => {
        })
      },
      editData(index, row) {
        //清空历史值
        this.formData = {
          companyName: '',
          employeeName: '',
          telphone: '',
          region: '',
          businessLicense: {},
          companyLogo: {},
          idCards: [],
          applicants: {},
          address: ''
        }
        let that = this
        that.actionType = 'edit'
        this.loading = true
        rescueCompanyApi.getOperationById(row.id, (res1) => {
          that.formData = res1
          that.formData.id = row.id
          if(this.formData.region){
            const sh = TextToCode[this.formData.region.split(',')[0]]
            const s = TextToCode[this.formData.region.split(',')[0]][this.formData.region.split(',')[1]]
            this.selectedOptions.push(sh.code)
            if (typeof(s) !== 'undefined') {
              this.selectedOptions.push(s.code)
            }
          }
          this.logoImgs = []
          if (this.formData.companyLogo != null) {
            let logoImg = {
              url: this.baseUrl + this.formData.companyLogo.url
            }
            this.logoImgs.push(logoImg)
          }
          this.qrcodeImgs = []
          if (this.formData.companyMpQrcode != null) {
            let qrcodeImg = {
              url: this.baseUrl + this.formData.companyMpQrcode.url
            }
            this.qrcodeImgs.push(qrcodeImg)
          }
          this.businessImgs = []
          if (this.formData.businessLicense != null) {
            let businessImg = {
              url: this.baseUrl + this.formData.businessLicense.url
            }
            this.businessImgs.push(businessImg)
          }
          this.loading = false
          that.dialogFormVisible = true
        }, () => {

        })
      },
      viewData(index, row) {
        //清空历史值
        this.formData = {
          companyName: '',
          employeeName: '',
          telphone: '',
          region: '',
          businessLicense: {},
          companyLogo: {},
          idCards: [],
          applicants: {},
          address: ''
        }
        let that = this
        that.actionType = 'edit'
        this.loading = true
        rescueCompanyApi.getOperationById(row.id, (res1) => {
          that.formData = res1
          that.formData.id = row.id
          if(this.formData.region){
            const sh = TextToCode[this.formData.region.split(',')[0]]
            const s = TextToCode[this.formData.region.split(',')[0]][this.formData.region.split(',')[1]]
            this.selectedOptions.push(sh.code)
            if (typeof(s) !== 'undefined') {
              this.selectedOptions.push(s.code)
            }
          }
          this.loading = false
          that.dialogViewFormVisible = true
        }, () => {

        })
      },
      handleEdit() {
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.formData.region = CodeToText[this.selectedOptions[0]] + "," + CodeToText[this.selectedOptions[1]]
            rescueCompanyApi.updateBaseRescueCompany(this.formData.id, this.formData, (res) => {
              this.loading = false
              this.dialogFormVisible = false
              this.$message({
                message: '修改成功',
                type: 'success'
              })
              this.initData()
            }, () => {
              this.loading = false
            })
          }
        })
      },
      editManager(index, row) {
        this.formManagerData.newManagerId = ''
        this.formManagerData.telphone = ''
        rescueEmployeeApi.listAllRescueDriver(row.id, (res) => {
          this.allDriverData = res
          this.formManagerData.companyId = row.id
          this.dialogManagerFormVisible = true
        }, () => {
        })
      },
      handleManager() {
        this.loading = true
        rescueEmployeeApi.updateRescueCompanyManager(this.formManagerData, (res) => {
          this.loading = false
          this.dialogManagerFormVisible = false
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.initData()
        }, () => {
          this.loading = false
        })
      },
      handleDelete(index, row) {
        this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          rescueCompanyApi.deleteSingleRescueCompany(row.id, (res) => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.initData()
          }, () => {
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.listTableData()
      },
      handleCurrentChange(val) {
        this.currentPage = val
        this.listTableData()
      },
      handleSelectionChange(val) {
        this.multipleSelection = []
        for (var ms of val) {
          this.multipleSelection.push(ms.id)
        }
      },
      deleteAny() {
        if (this.multipleSelection.length == 0) {
          this.$message({
            type: 'warning',
            message: '请选择记录!'
          })
          return;
        }
        this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          rescueCompanyApi.removeRescueCompany(this.multipleSelection, (res) => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.initData()
          }, () => {
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
      managerSelectChange(value) {
        for (var d of this.allDriverData) {
          if (d.id == value) {
            this.formManagerData.telphone = d.telphone
            break
          }
        }
      }
    }
  }
</script>
